package com.bah.tract.service;

import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class DateProperty extends Property {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public DateProperty(final String name, final Date value) {
		setType(PropertyType.DATE_TIME);
		final GregorianCalendar c = new GregorianCalendar();
		c.setTime(value);
		try {
			final XMLGregorianCalendar date = DatatypeFactory.newInstance()
					.newXMLGregorianCalendar(c);
			setDateTimeValue(date);
		} catch (final DatatypeConfigurationException e) {
			throw new IllegalArgumentException(e);
		}
		setName(name);
	}

	@Override
	public final int hashCode() {
		return PropertyHashAndEquals.hashCode(this);
	}

	@Override
	public final boolean equals(final Object obj) {
		return PropertyHashAndEquals.equals(this, obj);
	}
}
